<?php
//流程控制器
class ProcessAction extends LeaveAction {
    /**
     * [processList description]模版跳转我的申请
     * @return [type] [description]
     */
    public function processList(){
    	$this->display('Process:processList');
    }

    /**
     * [processListData description]获取我的申请数据
     * @return [type] [description]
     */
    public function processListData(){
    	$result = array();
    	$result['total'] = $this->getListCount();
    	$result['rows'] = $this->getList();
    	echo json_encode($result);
    }

    /**
     * 获取列表我的申请列表  process_state!=0不等于保存的草稿  !=1为不在审核当中已经结束  process_now_id_approval=0为审核中的最新一条流程
     */
    public function getList()
    {
        $result=array();
        $employe_id=session('employe_id');
    	import("ORG.Util.Page");
    	$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    	$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
       	$process=M('Process');
       	$data=$process->where("process_begin_id='".$employe_id."' and process_state!=0 and (process_state!=1 or process_now_id_if_approval=0)")->page($page,$rows)->order('process_time desc')->select();
        foreach ($data as $value) {
            $value['process_now_id']=$this->getOneEmployeName($value['process_now_id']);
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['process_state']=$this->judgeState($value['process_state']);
            $result[]=$value;
        }
        return $result;
    }
    
    /**
     * 获取列表数量
     */
    public function getListCount()
    {	
        $employe_id=session('employe_id');
    	$process=M('Process');
    	$result=$process->where("process_begin_id='".$employe_id."' and process_state!=0 and (process_state!=1 or process_now_id_if_approval=0)")->count();
        return $result;
    }

    
    /**
     * 用户获得个人所有流程信息，包括已提交的流程和保存为草稿的流程
     * 物品资产流程从goods表中获取，公文流程从document表中获取，请假流程从leave表中获取
     */
    /*获得已提交流程*/
    public function getPersonalProcess(){
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $employe_id=$_SESSION['employe_id'];//通过session获得当前员工id
        $m=M("process");
        $total=$m->where("process_begin_id=".$employe_id." and process_state!=0 and process_parent_id=0")->count();
        $process=$m->where("process_begin_id=".$employe_id." and process_state!=0 and process_parent_id=0")->order("process_id desc")->limit(($page-1)*$rows.",".$rows)->select();
        if(0==$total){
            $process=array();
        }
        $data['total']=$total;
        $data['rows']=$process;
        echo json_encode($data);
    }
    /*获得保存流程*/
    public function getPersonalProcess1(){
        $page=$_POST['page'];
        $rows=$_POST['rows'];
        $employe_id=$_SESSION['employe_id'];//通过session获得当前员工id
        $m=M("process");
        $total=$m->where("process_begin_id=".$employe_id." and process_state=0 and process_parent_id=0")->count();
        $process=$m->where("process_begin_id=".$employe_id." and process_state=0 and process_parent_id=0")->order("process_id desc")->limit(($page-1)*$rows.",".$rows)->select();
        if(0==$total){
            $process=array();
        }
        $data['total']=$total;
        $data['rows']=$process;
        echo json_encode($data);
    }

    /*获得流程详细内容*/
    public function getProcessContent(){
        $processType=$_GET['processType'];
        $processId=$_GET['processId'];
        if('goods'==$processType){
            $m=M('goods');
            $goods=$m->where('goods_process_id='.$processId)->field('goods_id,goods_type')->find();
            $goodsId=$goods['goods_id'];
            $goodsType=$goods['goods_type'];
            if(1==$goodsType){
                $processContent=M('getgoods')->where('getgoods_goods_id='.$goodsId)->select();
                if(fasle==$processContent){
                   $this->display('common/processContentTableError');
                }else{
                    $this->assign('processContent',$processContent);
                    $this->display('common/getGoodsTable');
                }
            }else if(2==$goodsType){
                $processContent=M('buygoods')->where('buygoods_goods_id='.$goodsId)->select();
                if(fasle==$processContent){
                     $this->display('common/processContentTableError');
                }else{
                    $this->assign('processContent',$processContent);
                    $this->display('common/buyGoodsTable');
                }
            }else{
                $processContent=M('repair')->where('repair_goods_id='.$goodsId)->select();
                if(fasle==$processContent){
                     $this->display('common/processContentTableError');
                }else{
                    $this->assign('processContent',$processContent);
                    $this->display('common/repairTable');
                }
            }
        }else{
            $processContent=M($processType)->where($processType.'_process_id='.$processId)->find();
            if(fasle==$processContent){
                $this->display('common/processContentTableError');
            }else{
                $this->assign('processContent',$processContent);
                $this->display('common/'.$processType.'Table');
            }
        }
    }

    /*提交草稿流程*/
    public function submitProcess(){
        $processID=$_POST['processID'];
        $processType=$_POST['processType'];
        $m=M($processType);
        $data[$processType.'_state']=1;
        $count=$m->where($processType.'_process_id='.$processID)->save($data);
        if(false==$count){
            echo 0;
            exit;
        }
        $m=M("process");
        $data1['process_state']=1;
        $count1=$m->where("process_id=".$processID)->save($data1);
        if(false==$count1){
            echo 0;
        }else{
            echo 1;
        }
    }

    /*查看流程状态*/
    public function processState(){
        $processID=$_POST['processID'];
        $processNum=M('process')->where('process_id='.$processID)->getField('process_num');
        $state=M('process')->where('process_num='.$processNum)->select();
        var_dump($state);
    }

    /**
     * [processList description]模版跳转代办流程
     * @return [type] [description]
     */
    public function processCheckList(){
        $this->display('Process:processCheckList');
    }

    /**
     * [processListData description]获取我的审批列表数据
     * @return [type] [description]
     */
    public function processListCheckData(){
        $result = array();
        $result['total'] = $this->getListCheckCount();
        $result['rows'] = $this->getCheckList();
        echo json_encode($result);
    }

    /**
     * 获取列表
     */
    public function getCheckList()
    {
        $employe_id=session('employe_id');
        import("ORG.Util.Page");
        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
        $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $result=array();
        $process=M('Process');
        $data=$process->where("process_now_id='".$employe_id."' and process_now_id_if_approval=0")->page($page,$rows)->order('process_time desc')->select();
        foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['process_now_id']=$this->getOneEmployeName($value['process_now_id']);
            $value['process_state']=$this->judgeState($value['process_state']);
            $result[]=$value;
        }
        return $result;
    }
    
    /**
     * 获取列表数量
     */
    public function getListCheckCount()
    {   
        $employe_id=session('employe_id');
        $process=M('Process');
        $result=$process->where("process_now_id='".$employe_id."' and process_now_id_if_approval=0")->count();
        return $result;
    }

    /**
     * [checkProcess description]审批模版跳转
     * @return [type] [description]
     */
    public function checkProcess(){
        $process_type=I('process_type');//申请表类型
        $last_process_id=I('process_id');//最后一次审批id
        $process_num=I('process_num');//申请流程号

        $process=M('Process');
        $process_id=$process->where("process_num='".$process_num."' and process_parent_id=0")->getField("process_id");//提交申请的那条流程 第一条id

        $this->assign('process_id',$process_id);
        $this->assign('process_num',$process_num);
        $this->assign('employe_id',session('employe_id'));

        /*****************注意套用开始($process_type)***********************/
        $model=M($process_type);
        $data=$model->where(strtolower($process_type)."_process_id='".$process_id."'")->select();
        $this->assign("data",$data);//申请表数据

        //处理mkk的部分
        $this->goodsCurl($process_type,$process_id);
        

        $process_begin_id=$process->where("process_id='".$process_id."'")->getField('process_begin_id');
        $employe=M('Employe');
        $field=$employe->where("employe_id='".$process_begin_id."'")->field('employe_department_id','employe_position_id','employe_id')->find();
        $employe_department_id=$employe->where("employe_id='".$process_begin_id."'")->getField('employe_department_id');

        $this->assign('department',$this->getDepartmentName($employe_department_id));//申请人部门名称
        $this->assign('position',$this->getPositionName($field['employe_position_id']));//申请人职位名称
        $this->assign('employeName',$this->getOneEmployeName($field['employe_id']));//申请人姓名
        

        $this->processData=$process->where("process_id='".$last_process_id."'")->select();//流程信息

        $this->getAllApproval($process_num);

        $this->judgeLastApproval($process_type,$process_num,$process_id);//如果是最后一次审批那么sign为over模版就不显示选择下一步的审核人

        $this->display("Approval:process".$process_type);
        /*****************注意套用结束***********************/
    }


    /**
     * [goodsCurl description]处理mkk部分
     * @param  [type] $process_type [description]
     * @return [type]               [description]
     */
    public function goodsCurl($process_type,$process_id){
        if(strtolower($process_type)=='goods'){
            $goods=M('Goods');
            $goods_type=$goods->where("goods_process_id='".$process_id."'")->getField('goods_type');
            $goods_id=$goods->where("goods_process_id='".$process_id."'")->getField('goods_id');
            //领用物品
            if($goods_type==1){
                $getgoods=M('Getgoods');
                $this->getgoodsData=$getgoods->where("getgoods_goods_id='".$goods_id."'")->select();
                $this->assign('goods',1);
            }
            //购买物品
            if($goods_type==2){
                $buygoods=M('Buygoods');
                $this->buygoodsData=$buygoods->where("buygoods_goods_id='".$goods_id."'")->select();
                $this->assign('goods',2);
            }
            //维修物品
            if($goods_type==3){
                $repair=M('Repair');
                $this->repairData=$repair->where("repair_goods_id='".$goods_id."'")->select();
                $this->assign('goods',3);
            }
        }
    }


    /**
     * [getAllApproval description]获取所有的审核流程(不包括正在审核的)
     * @param  [type] $process_num [description]
     * @return [type]              [description]
     */
    public function getAllApproval($process_num){
        $model=new Model();
        $this->allApprovalData=$model->table('oa_process op,oa_employe oe')->where("op.process_now_id=oe.employe_id and op.process_num='".$process_num."' and op.process_now_id_if_approval=1")->order('process_approval_time')->select();
    }

    /**
     * [judgeLastApproval description]判断是否是最后一次审批如果是最后一次审批那么sign为over模版就不显示选择下一步的审核人
     * @param  [type] $process_type [description]
     * @param  [type] $process_id   [description]
     * @return [type]               [description]
     */
    public function judgeLastApproval($process_type,$process_num,$process_id){
        $count=$this->getApprovalCount($process_num);//获取已审批次数
        if(strtolower($process_type)=="leave"){
            $leave=M('Leave');
            $date=$leave->where("leave_process_id='".$process_id."'")->getField('leave_date_num');//请假天数
            if($date<=1){
                $this->assign('sign','over');
            }
            if($date>1 and $date<=3) {
                if($count==2){
                    $this->assign('sign','over');
                }
            }
            if($date>3){
                if($count==3){
                    $this->assign('sign','over');
                }
            }
        }
        /*****************注意套用开始(根据process_type判断审批次数判断当前审批是否是最后一次 sign="over"标记最后一次)***********************/
        if(strtolower($process_type)=="document"){
            if($count==2){
                $this->assign('sign','over');
            }
        }
        
        if(strtolower($process_type)=="goods"){
            if($count==3){
                $this->assign('sign','over');
            }
        }
    }

    /**
     * [getApprovalCount description]获取审批的次数
     * @param  [type] $process_id [description]
     * @return [type]             [description]
     */
    public function getApprovalCount($process_num){
        $process=M("Process");
        $count=$process->where("process_num='".$process_num."'")->count();
        return $count;
    }

    /**
     * [doApproval description]审批
     * @return [type] [description]
     */
    public function doApproval(){
        //echo '审批完成';
        $process=M('Process');
        $result=$process->where("process_num='".I('process_num')."' and process_now_id_if_approval=1 and process_now_id='".session('employe_id')."'")->find();//判断是否已经审核了
        if($result){
            echo '已经审核';
        }
        else{
            $process->process_num=I('process_num');
            $process->process_title=I('process_title');
            $process->process_begin_id=I('process_begin_id');
            $process->process_time=I('process_time');
            $process->process_type=I('process_type');
            $process->process_now_id_if_approval=0;
            $process->process_parent_id=I('process_id');
            $process->process_now_id=I('check_person_id');
            
            if(I('check_person_id')){//判断是否是最后一次审核(check_person_id为空说明没有这个选人的文本框是最有一次提交)
                if(I('process_approval')==0)//不予批准
                {
                    $this->changeXstate(I('process_type'),I('process_num'),2);
                    $this->changeNowIdIfapproval(I('process_id'),I('process_approval'),I('process_remark'),$_POST['process_sign_name'],2);

                    $msg_from_name=$this->getOneEmployeName(I('process_now_id'));
                    $msg_title=I('process_title');
                    $msg_content=$msg_from_name.'不予批准你的'.$msg_title;
                    if(I('msg_tip')){
                        //发送消息
                        $this->sendMsg(I('process_begin_id'),I('process_now_id'),$msg_title,$msg_content);
                    }

                    if(I('msg_phone')){
                        //发送短信
                        $mobile=I('phone_num');
                        $content=$msg_content."【来自丽丰OA系统】";
                        $mobileids=$mobile.strval(time());
                        $this->sendSMS($mobile,$content,$mobileids);
                    }
                    echo '审批完成';
                }
                if(I('process_approval')==1)//批准
                {
                    $this->changeXstate(I('process_type'),I('process_num'),1);
                    $process->process_state=1;
                    $this->changeNowIdIfapproval(I('process_id'),I('process_approval'),I('process_remark'),$_POST['process_sign_name'],1);
                    if($process_id=$process->add())

                        $msg_from_name=$this->getOneEmployeName(I('process_now_id'));
                        $msg_title=I('process_title');
                        $msg_content=$msg_from_name.'向您转提了一条'.$msg_title.'请注意查收';
                        if(I('msg_tip')){
                            //发送消息
                            $this->sendMsg(I('check_person_id'),I('process_now_id'),$msg_title,$msg_content);
                        }

                        if(I('msg_phone')){
                            //发送短信
                            $mobile=I('phone_num');
                            $content=$msg_content."【来自丽丰OA系统】";
                            $mobileids=$mobile.strval(time());
                            $this->sendSMS($mobile,$content,$mobileids);
                        }
                        echo '审批完成';
                }
            }
            else{
                if(I('process_approval')==0)//不予批准
                {
                    $this->changeXstate(I('process_type'),I('process_num'),2);
                    $this->changeNowIdIfapproval(I('process_id'),I('process_approval'),I('process_remark'),$_POST['process_sign_name'],2);


                    $msg_from_name=$this->getOneEmployeName(I('process_now_id'));
                    $msg_title=I('process_title');
                    $msg_content=$msg_from_name.'不予批准你的'.$msg_title;
                    if(I('msg_tip')){
                        //发送消息
                        $this->sendMsg(I('process_begin_id'),I('process_now_id'),$msg_title,$msg_content);
                    }

                    if(I('msg_phone')){
                        //发送短信
                        $mobile=I('phone_num');
                        $content=$msg_content."【来自丽丰OA系统】";
                        $mobileids=$mobile.strval(time());
                        $this->sendSMS($mobile,$content,$mobileids);
                    }
                    echo '审批完成';
                }
                if(I('process_approval')==1)//批准
                {
                    $this->changeXstate(I('process_type'),I('process_num'),3);
                    $this->changeNowIdIfapproval(I('process_id'),I('process_approval'),I('process_remark'),$_POST['process_sign_name'],3);

                    $msg_from_name=$this->getOneEmployeName(I('process_now_id'));
                    $msg_title=I('process_title');
                    $msg_content=$msg_from_name.'批准了你的'.$msg_title;
                    if(I('msg_tip')){
                        //发送消息
                        $this->sendMsg(I('process_begin_id'),I('process_now_id'),$msg_title,$msg_content);
                    }

                    if(I('msg_phone')){
                        //发送短信
                        $mobile=I('phone_num');
                        $content=$msg_content."【来自丽丰OA系统】";
                        $mobileids=$mobile.strval(time());
                        $this->sendSMS($mobile,$content,$mobileids);
                    }
                    //发送消息
                   echo '审批完成';
                }
            }
        }
        
    }

    /**
     * [changeNowIdIfapproval description]标记当前审核人员的流程记录为已审核
     * @param  [type] $process_id [description]
     * @return [type]             [description]
     */
    public function changeNowIdIfapproval($process_id,$process_approval,$process_remark,$process_sign_name,$process_state){
        $process=M('Process');
        $data['process_now_id_if_approval']=1;
        $data['process_approval']=$process_approval;
        $data['process_remark']=$process_remark;
        $data['process_sign_name']=$process_sign_name;
        $data['process_approval_time']=time();
        $data['process_state']=$process_state;
        $process->where("process_id='".$process_id."'")->save($data);        
    }

    /**
     * [changeXstate description]修改申请表中的状态，审核后都会更新
     * @param  [type] $porcess_type [description]
     * @param  [type] $porcess_num  [description]
     * @param  [type] $state        [description]当前审核动作的状态
     * @return [type]               [description]
     */
    public function changeXstate($process_type,$process_num,$state){
        $process=M('Process');
        $process_id=$process->where("process_num='".$process_num."' and process_parent_id=0")->getField("process_id");
        /*****************注意套用开始(_state  _process_id 这几个字段要按这样的格式来)***********************/
        $model=M($process_type);
        $data[strtolower($process_type).'_state']=$state;
        $model->where(strtolower($process_type)."_process_id ='".$process_id."'")->save($data);
        /*****************注意套用开始($process_type)***********************/
    }


    /**
     * [processList description]跳转已办流程
     * @return [type] [description]
     */
    public function processCheckedList(){
        $this->display('Process:processCheckedList');
    }

    /**
     * [processListData description]获取已办流程列表数据
     * @return [type] [description]
     */
    public function processListCheckedData(){
        $result = array();
        $result['total'] = $this->getListCheckedCount();
        $result['rows'] = $this->getCheckedList();
        echo json_encode($result);
    }

    /**
     * 获取列表数量
     */
    public function getListCheckedCount()
    {   
        $employe_id=session('employe_id');
        $process=M('Process');
        $result=$process->where("process_now_id='".$employe_id."' and process_state!=0 and (process_state!=1 or process_now_id_if_approval=1)")->count();
        return $result;
    }


    /**
     * 获取列表
     */
    public function getCheckedList()
    {
        $employe_id=session('employe_id');
        import("ORG.Util.Page");
        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
        $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $result=array();
        $process=M('Process');
        $data=$process->where("process_now_id='".$employe_id."' and process_state!=0 and (process_state!=1 or process_now_id_if_approval=1)")->page($page,$rows)->order('process_time desc')->select();

        foreach ($data as $value) {
            //获取当前或最后一位审批的人员
            $field=$process->where("process_num='".$value['process_num']."' and process_state!=0 and (process_state!=1 or process_now_id_if_approval=0)")->field('process_now_id,process_state')->find();
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['process_now_id']=$this->getOneEmployeName($field['process_now_id']);
            $value['process_state']=$this->judgeState($field['process_state']);
            $result[]=$value;
        }
        return $result;
    }



    /**
     * [searchDetail description]我的申请查看申请详情
     * @return [type] [description]
     */
    public function searchDetail(){
        $process_type=I('process_type');//申请表类型
        $last_process_id=I('process_id');//最后一次审批id
        $process_num=I('process_num');//申请流程号

        $process=M('Process');
        $process_id=$process->where("process_num='".$process_num."' and process_parent_id=0")->getField("process_id");

        $this->assign('process_id',$process_id);
        $this->assign('process_num',$process_num);

        /*****************注意套用开始($process_type)***********************/
        $model=M($process_type);
        $data=$model->where(strtolower($process_type)."_process_id='".$process_id."'")->select();
        $this->assign("data",$data);//申请表数据

        //处理mkk的部分
        $this->goodsCurl($process_type,$process_id);

        $process_begin_id=$process->where("process_id='".$process_id."'")->getField('process_begin_id');
        $employe=M('Employe');
        $field=$employe->where("employe_id='".$process_begin_id."'")->field('employe_department_id','employe_position_id','employe_id')->find();
        $employe_department_id=$employe->where("employe_id='".$process_begin_id."'")->getField('employe_department_id');

        $this->assign('department',$this->getDepartmentName($employe_department_id));//申请人部门名称
        $this->assign('position',$this->getPositionName($field['employe_position_id']));//申请人职位名称
        $this->assign('employeName',$this->getOneEmployeName($field['employe_id']));//申请人姓名

        

        $this->processData=$process->where("process_id='".$last_process_id."'")->select();//流程信息

        $this->getAllDetail($process_num);/**********区别审判模版 显示未审批的流程,显示所以的记录***************/

        $this->judgeLastApproval($process_type,$process_num,$process_id);//如果是最后一次审批那么sign为over模版就不显示选择下一步的审核人

        $this->judgeLastIfApproval($process_num);

        $this->assign('detail','true');/***********区分审判查看流程详情还是我的申请查看详情模版***************/

        $this->display("Approval:process".$process_type);
        /*****************注意套用开始($process_type)***********************/
    }

    /**
     * [judgeLastIfApproval description]判断最后一次是否审核了
     * @param  [type] $process_num [description]
     * @return [type]              [description]
     */
    public function judgeLastIfApproval($process_num){
        $process=M('Process');
        $result=$process->where("process_num='".$process_num."' and process_now_id_if_approval=0")->find();
        if($result){
            $this->assign('lastIfApproval','ok');
        }
        else{
            $this->assign('lastIfApproval','no');
        }
    }


    /**
     * [getAllDetail description]获取所有的审核流程
     * @param  [type] $process_num [description]
     * @return [type]              [description]
     */
    public function getAllDetail($process_num){
        $model=new Model();
        $this->allApprovalData=$model->table('oa_process op,oa_employe oe')->where("op.process_now_id=oe.employe_id and op.process_num='".$process_num."'")->order('process_approval_time')->select();
    }


    public function draftApproval(){
        $this->display("Process:processDraft");
    }

    /**
     * [DraftApprovalData description]获取草稿箱列表
     * @return [type] [description]
     */
    public function DraftApprovalData(){
        $result = array();
        $result['total'] = $this->getListDraftCount();
        $result['rows'] = $this->getDraftList();
        echo json_encode($result);
    }

    /**
     * 获取列表
     */
    public function getDraftList()
    {
        $result=array();
        $employe_id=session('employe_id');
        import("ORG.Util.Page");
        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
        $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $process=M('Process');
        $data=$process->where("process_begin_id='".$employe_id."' and process_state=0")->page($page,$rows)->select();
        foreach ($data as $value) {
            $value['process_now_id']=$this->getOneEmployeName($value['process_now_id']);
            $result[]=$value;
        }
        return $result;
    }
    
    /**
     * 获取列表数量
     */
    public function getListDraftCount()
    {   
        $employe_id=session('employe_id');
        $process=M('Process');
        $result=$process->where("process_begin_id='".$employe_id."' and process_state=0")->count();
        return $result;
    }

    /**
     * [editDraft description]编辑保存的流程模版 模版跳转
     * @return [type] [description]
     */
    public function editDraft(){
        $process_id=I('process_id');
        $process_type=I('process_type');

        $model=M($process_type);
        $this->approvalData=$model->where(strtolower($process_type)."_process_id='".$process_id."'")->select();//申请表内的数据

        $process=M('Process');
        $this->processData=$process->where("process_id='".$process_id."'")->select();
        $process_now_id=$process->where("process_id='".$process_id."'")->getField("process_now_id");
        $process_now_name=$this->getOneEmployeName($process_now_id);
        $this->assign('process_now_name',$process_now_name);
        

        $employe_id=session('employe_id');
        $this->nowEmployeData=$this->getNowEmploye($employe_id);

        $employe_position_id=$this->getOneField('employe_position_id',$employe_id);
        $position_name=$this->getPositionName($employe_position_id);
        $this->assign('employe_position_id',$employe_position_id);
        $this->assign('position_name',$position_name);

        $employe_department_id=$this->getOneField('employe_department_id',$employe_id);
        $dpt_name=$this->getDepartmentName($employe_department_id);
        $this->assign('employe_department_id',$employe_department_id);
        $this->assign('dpt_name',$dpt_name);

        $this->display('Leave:editLeave');
    }

    /**
     * [delDraft description]删除保存的流程
     * @return [type] [description]
     */
    public function delDraft(){
        $process=M('Process');
        $process_id=I('process_id');
        $process_type=I('process_type');

        $model=M($process_type);
        $result1=$model->where(strtolower($process_type)."_process_id='".$process_id."'")->delete();//申请表数据删除

        $result2=$process->where("process_id ='".$process_id."'")->delete();//流程表数据删除
        
    }

    public function sumbitDraft(){
        $process=M('Process');
        $number=$_POST['process_num'];
        $process_type=I('process_type');
        $model=M($process_type);
        $result_second=$process->where("process_num='".$number."' and process_state=0")->find();//如果已经保存了
        if($result_second){
            $dataProcess['process_state']=1;
            $data[strtolower($process_type)."_state"]=1;
            $process->where("process_num='".$number."'")->save($dataProcess);
            $field=$process->where("process_num='".$number."'")->field('process_id,process_begin_id,process_now_id,process_title')->find();
            $model->where(strtolower($process_type)."_process_id='".$field['process_id']."'")->save($data);

            $msg_from_name=$this->getOneEmployeName($field['process_begin_id']);
            $msg_title=$field['process_title'];
            $msg_content=$msg_title.$msg_from_name.'向您提交了一条申请，请注意查收';
            $this->sendMsg($field['process_now_id'],$field['process_begin_id'],$msg_title,$msg_content);
            
            echo '申请成功！';
        }
    }
}